package cn.kgc.houseweb.controller;


import cn.kgc.bean.System;
import cn.kgc.bean.*;
import cn.kgc.service.*;
import cn.kgc.utils.*;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@CrossOrigin
public class HouseController {

    @Reference
    HouseService houseService;
    @Reference
    LiverService liverService;
    @Reference
    RoomService roomService;
    @Reference
    LiverOrderService liverOrderService;
    /*登录*/
    @RequestMapping("/house/login")
    public ResultEntity login(String username, String password){
        Manage login = houseService.login(username, password);
        if (login==null){
            return ResultEntity.successWithoutData("faild");
        }else{
           if (login.getState()<=0){
               return ResultEntity.successWithoutData("stateno");
           }else{
               return ResultEntity.successWithoutData(login);
           }
        }
    }
    //*注册公寓*//*
   @RequestMapping("house/regist")
    public ResultEntity regist(@RequestBody CourceEntity courceEntity){
        House house=courceEntity.getHouse();
        Manage manage=courceEntity.getManager();
       if (house==null) {
           java.lang.System.out.println("未接受到house值");
       }
        if (manage==null){
            java.lang.System.out.println("未接受到manage值");
            return ResultEntity.successWithoutData("系统错误");

        }else{

            int i = houseService.registHouse(house,manage);
            if (i==2){
                return ResultEntity.successWithoutData("success");
            }else{
                if (i==1){
                    return ResultEntity.successWithoutData("公寓名称["+house.getHousename()+"]已被注册,您可以尝试更改为公寓英文名或者公寓名字内容增加其他符号!");
                }else{
                    if (i==3){
                        return ResultEntity.successWithoutData("系统错误");
                    }else{
                        if (i==0){
                            return ResultEntity.successWithoutData("管理员帐号["+manage.getUsername()+"]已存在,请尝试更换帐号");
                        }else{
                            return ResultEntity.successWithoutData("验证码错误,请检查");
                        }
                    }
                }
            }
        }
    }
    /*发送注册验证码*/
    @RequestMapping("/house/sendCode")
    public ResultEntity sendCode(String phone ){
        Map<String,Object> map=new HashMap<>();
        String code = houseService.sendCode(phone);
        if (code!=null){
            map.put("result","success");
            map.put("code",code);
            map.put("phone",phone);

        }else{
            map.put("result","faild");
        }
        return ResultEntity.successWithoutData(map);
    }

    //查询
    @RequestMapping("/selectHouse")
    public ResultEntity<PageInfo<House>> selectHouse(@RequestParam(value = "pageNum",required =false,defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "pageSize",required =false,defaultValue = "3") Integer pageSize,
                                                     @RequestParam(value = "frname",required = false,defaultValue = "")String frname,
                                                     @RequestParam(value = "housename",required = false,defaultValue = "")String housename,
                                                     @RequestParam(value = "houseaddr",required = false,defaultValue = "")String houseaddr){
        PageInfo<House> pageInfo=houseService.selectAllHouse(pageNum, pageSize, frname, housename, houseaddr);
        return ResultEntity.successWithoutData(pageInfo);
    }
    /*增加公寓*/
    @RequestMapping("/addHouse")
    public ResultEntity<String> addHouse(@RequestBody House house){
        try {
            Integer integer=0;
            if (house.getId()==null){
                integer=houseService.addHouse(house);
            }else {
                integer=houseService.updateHouse(house);
            }
            return ResultEntity.successWithoutData(integer+"");
        }catch (Exception exception){
            return ResultEntity.failed(exception.getMessage());
        }

    }

    /*根据公寓id获取公寓信息*/
    @RequestMapping("/getHouseById")
    public ResultEntity<House> getHouseById(Integer id){
        House house=houseService.selectById(id);
        return ResultEntity.successWithoutData(house);
    }


/*根据公寓id删除公寓*/
    @RequestMapping("/deleteHouseById")
    public ResultEntity<String> deleteHouseById(Integer id){
        try {
            Integer delhouse=houseService.delHouse(id);
            return ResultEntity.successWithoutData(delhouse+"");
        }catch (Exception exception){
            return ResultEntity.failed(exception.getMessage());
        }
    }
    /*根据登录用户名查询公寓信息*/
    @RequestMapping("house/selectHouseByLoginName")
    public ResultEntity selectHouseByLoginName(String loginName){
        Map<String,Object> map=new HashMap<>();
        Manage manage = houseService.selectZmanagerByUsername(loginName);
        if (manage!=null){
            House house = houseService.selectById(manage.getHouseid());
            map.put("result","success");
            map.put("manage",manage);
            map.put("house",house);
            return ResultEntity.successWithoutData(map);
        }else{
            map.put("result","null");
            return ResultEntity.successWithoutData(map);
        }
    }
    /*获取系统信息*/
    @RequestMapping("house/getSystem")
    public ResultEntity getSystem(){
        System system = houseService.selectSystem();
        return ResultEntity.successWithoutData(system);
    }
    /*住户入住登记(一)*/
    @RequestMapping("house/add1")
    public ResultEntity add1(Integer liverid,Integer roomid,Integer houseid){
        int i = houseService.add1(liverid, roomid, houseid);
        if (i==2){
            return ResultEntity.successWithoutData("success");
        }else{
            if (i==0){
                return ResultEntity.successWithoutData("编号为:["+liverid+"]的用户不存在");
            }else{
                if (i==1){
                    return ResultEntity.successWithoutData("编号为:["+liverid+"]的用户未绑定本公寓");
                }else{
                  if (i==3){
                      return ResultEntity.successWithoutData("操作失败,系统错误!");
                  }else{
                      if (i==4){
                          return ResultEntity.successWithoutData("编号为:["+roomid+"]的房间不属于本公寓");
                      }else{
                          if (i==5){
                              return ResultEntity.successWithoutData("编号为:["+roomid+"]的房间不存在");
                          }else{
                              if (i==6){
                                  return ResultEntity.successWithoutData("编号为:["+roomid+"]的房间人数已满");
                              }else{
                                  return ResultEntity.successWithoutData("操作失败,系统错误!");
                              }
                          }
                      }
                  }
                }
            }
        }
    }
    /*住户入住登记(二)*/
    @RequestMapping("house/add2")
    public ResultEntity add2(@RequestBody Liver liver){
        int i = houseService.add2(liver);
        if (i==2){
            return ResultEntity.successWithoutData("success");
        }else{
            if (i==0){
                return ResultEntity.successWithoutData("手机号["+liver.getPhone()+"]已被注册");
            }else{
                if (i==1){
                    return ResultEntity.successWithoutData("房间编号["+liver.getRoomid()+"]不存在");
                }else{
                    if (i==3){
                        return ResultEntity.successWithoutData("编号为:["+liver.getRoomid()+"]的房间不属于本公寓管理");
                    }else{
                        if (i==4){
                            return ResultEntity.successWithoutData("编号为:["+liver.getRoomid()+"]的房间人数已满!");
                        }else{
                            return ResultEntity.successWithoutData("系统错误!");
                        }
                    }
                }
            }
        }

    }
    /*管理员注册*/
    @RequestMapping("house/manageregist")
    public ResultEntity manageregist(@RequestBody Manage manage){
        int result = houseService.houseregist(manage);
        if (result==2){
            return ResultEntity.successWithoutData("success");
        }else{
            if (result==0){
                return ResultEntity.successWithoutData("用户名["+manage.getUsername()+"]已存在,请尝试更换其他用户名");
            }else{
                if(result==1){
                    return ResultEntity.successWithoutData("编号为:["+manage.getHouseid()+"]的公寓不存在");
                }else{
                    return ResultEntity.successWithoutData("系统错误,请联系系统管理员!");
                }
            }
        }

    }
    /*发送邮箱验证码*/
    @RequestMapping("house/sendEmail")
    public ResultEntity sendEmail(String email){
        Map<String,Object> map=new HashMap<>();
        String code = houseService.sendEmail(email);
        if (code!=null){
            map.put("result","success");
            map.put("code",code);
            map.put("email",email);

        }else{
            map.put("result","faild");
        }
        return ResultEntity.successWithoutData(map);
    }
    /*公寓管理员绑定邮箱*/
    @RequestMapping("house/bindEmail")
    public ResultEntity bindEmail(String email,Integer id){
        int i = houseService.bindEmail(email, id);
        if (i==2){
            return ResultEntity.successWithoutData("success");
        }else{
            if (i==0){
                return ResultEntity.successWithoutData("该邮箱已被绑定在其他的管理帐号");
            }else{
                return ResultEntity.successWithoutData("系统错误");
            }

        }
    }
    /*密码找回*/
    @RequestMapping("house/forget")
    public ResultEntity forget(String email){
        int forget = houseService.forget(email);
        if (forget==2){
            return ResultEntity.successWithoutData("success");
        }else{
            if (forget==0){
                return ResultEntity.successWithoutData("该邮箱未绑定帐号");
            }else{
                return ResultEntity.successWithoutData("系统错误");
            }
        }
    }
    @RequestMapping("house/manage/passwordset")
    public String psswordset(String email,String code){
        Manage manage = houseService.getManageByEmail(email);
        if (manage!=null){
            if (manage.getCode().equals(code)){
                manage.setCode("NULL");
                houseService.updateZmanager(manage);
                return "<h2>MyHouse-公寓管理员密码重置</h2><form method='post' action='reset'><input type='hidden' name='id' value='"+manage.getId()+"'>输入新密码<input type='text' name='newpassword'><button type='submit'>确认</button></form><br><span style='color:red'>请勿刷新页面,本链接打开一次后将自动失效,无法再次打开</span>";
            }else{
                return "链接已失效";
            }
        }else{
            return "非法访问请求";
        }

    }
    /*密码重置*/
    @RequestMapping("house/manage/reset")
    public String reset(ResetEntity resetEntity){
        houseService.reset(resetEntity.getNewpassword(), resetEntity.getId());
        return "MyHouse提示:密码重置成功!<a href='http://localhost:8081/house_login.html'>点击跳转到登录页面</a>";
    }
    /*根据公寓id查询住户*/
    @RequestMapping("house/getlivers")
    public ResultEntity getlivers(@RequestParam(required = false,defaultValue = "1") Integer pageNum,@RequestParam(required = false,defaultValue = "10") Integer pageSize,Integer houseid,@RequestParam(defaultValue = "",required = false)String livername,@RequestParam(defaultValue = "0",required = false)Integer roomid){
        PageInfo<Liver> livers = houseService.getLivers(pageNum, pageSize, houseid,livername,roomid);
        return ResultEntity.successWithoutData(livers);
    }
    /*增加公寓房间*/
    @RequestMapping("house/addroom")
    public ResultEntity addroom(@RequestBody Room room){
        int addroom = houseService.addroom(room);
        if (addroom>0){
            return ResultEntity.successWithoutData("success");
        }else{
            return ResultEntity.successWithoutData("faild");
        }
    }
    /*修改公寓信息*/
    @RequestMapping("house/update")
    public ResultEntity updateHouse(@RequestBody House house){
        String housenote = house.getHousenote();
        if (housenote.contains("傻逼")||housenote.contains("脑残")||housenote.contains("废物")||housenote.contains("肏")){
            return ResultEntity.successWithoutData("ban");
        }
        Integer integer = houseService.updateHouse(house);
        if (integer>0){
            return ResultEntity.successWithoutData("success");
        }else{
            return ResultEntity.successWithoutData("faild");
        }

    }
    /*住户房间移动*/
    @RequestMapping("house/roomMove")
    public ResultEntity roomMOve(@RequestBody Liver liver){
        Liver oldLiverInfo = liverService.getLiverById(liver.getId());
        Room room1 = roomService.selectRoomById(liver.getRoomid());
        if (liver.getRoomid()==0||liver.getRoomid()==null){
            room1=new Room();
            room1.setId(0);
            room1.setHouseid(liver.getHouseid());
            room1.setRoomnow(0);
            room1.setRoomsize(5);
        }
        if (room1 != null) {
            if (room1.getRoomnow() >= room1.getRoomsize()) {
                return ResultEntity.successWithoutData("out");
            }
            if (room1.getHouseid() == liver.getHouseid()) {
                liver.setEndtime(new Date());
                int update = liverService.update(liver);
                if (update > 0) {
                    if (oldLiverInfo.getRoomid()!=null&&oldLiverInfo.getRoomid()!=0) {
                        Room room = roomService.selectRoomById(oldLiverInfo.getRoomid());
                        room.setRoomnow(room.getRoomnow() - 1);
                        int i = roomService.updateRoom(room);
                    }
                    if (room1.getId()==0){
                        return ResultEntity.successWithoutData("success");
                    }
                    room1.setRoomnow(room1.getRoomnow() + 1);
                    int i1 = roomService.updateRoom(room1);
                    if (i1 > 0) {
                        return ResultEntity.successWithoutData("success");
                    } else {
                        return ResultEntity.successWithoutData("faild");
                    }
                } else {
                    return ResultEntity.successWithoutData("运行错误:用户信息修改失败");
                }
            } else {
                return ResultEntity.successWithoutData("房间不属于本公寓管理,无法移动");
            }
        } else {
            return ResultEntity.successWithoutData("房间编号不存在");
        }
    }
    /*从公寓中删除住户*/
    @RequestMapping("house/deleteLiver")
    public ResultEntity deleteLiver(Integer id){
        Liver liverById = liverService.getLiverById(id);
        liverById.setHouseid(0);
        Room room = roomService.selectRoomById(liverById.getRoomid());
        room.setRoomnow(room.getRoomnow()-1);
        roomService.updateRoom(room);
        liverById.setRoomid(0);
        int update = liverService.update(liverById);

        return ResultEntity.successWithoutData("success");

    }
    /*根据公寓id查询所有房间信息*/
    @RequestMapping("house/getRooms")
    public ResultEntity getRooms(@RequestParam(required = false,defaultValue = "1") Integer pageNum,Integer houseid,@RequestParam(required = false,defaultValue = "") String roomname){
        Map<String,Object> map=new HashMap<>();
        try {
            PageInfo<Room> pageInfo = roomService.selectRoomByHouseInfo(pageNum, 10, houseid, roomname);
            map.put("result","success");
            map.put("pageinfo",pageInfo);
        } catch (Exception e) {
            map.put("result","faild");
            e.printStackTrace();
        }
        return ResultEntity.successWithoutData(map);
    }
    /*删除房间*/
    @RequestMapping("house/deleteRoom")
    public ResultEntity deleterRoom(Integer id){
         roomService.deleteRoomById(id);
        List<Liver> livers = liverService.selectLiverByRoomId(id);
        for (Liver liver : livers) {
            liver.setRoomid(0);
            liver.setEndtime(new Date());
            liverService.update(liver);
        }
        return ResultEntity.successWithoutData("success");
    }
    /*根据房间id查询房间信息*/
    @RequestMapping("house/getRoomById")
    public ResultEntity getRoomById(Integer id){
        Room room = roomService.selectRoomById(id);
        return ResultEntity.successWithoutData(room);

    }
    /*修改房间信息*/
    @RequestMapping("house/updateRoom")
    public ResultEntity updateRoom(@RequestBody Room room){
        int i = roomService.updateRoom(room);
        return ResultEntity.successWithoutData("success");

    }
    /*移除住户房间信息*/
    @RequestMapping("house/deleteLiverFromRoom")
    public ResultEntity deleteLiverFromRoom(Integer liverId){
        Liver liverById = liverService.getLiverById(liverId);
        Room room = roomService.selectRoomById(liverById.getRoomid());
        room.setRoomnow(room.getRoomnow()-1);
        roomService.updateRoom(room);
        liverById.setRoomid(0);
        liverService.update(liverById);
        return ResultEntity.successWithoutData("success");
    }
    /*查询住户订单记录*/
    @RequestMapping("house/getLiverOrders")
    public ResultEntity getLiverOrders(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                       @RequestParam(defaultValue = "0",required = false)Integer houseid,
                                       @RequestParam(required = false)Date startTime,
                                       @RequestParam(required = false)Date endTime,
                                       @RequestParam(defaultValue = "",required = false)String orderNo,
                                       @RequestParam(defaultValue = "",required = false)String liverName){
        PageInfo<Liverorder> pageInfo = null;
            pageInfo = liverOrderService.selectLiverOrders(pageNum, 10, houseid, startTime, endTime, orderNo, liverName);
        return ResultEntity.successWithoutData(pageInfo);
    }
    /*删除住户订单记录*/
    @RequestMapping("house/deleteLiverOrder")
    public ResultEntity deleteLiverOrder(Integer id){
        liverOrderService.deleteLiverOrderById(id);
        return ResultEntity.successWithoutData("success");
    }

    @Reference
    WxfkService wxfkService;
    /*获取维修反馈列表*/
    @RequestMapping("house/getWxfks")
    public ResultEntity getWxfks(@RequestParam(required = false)Integer id,
            @RequestParam(defaultValue = "1",required = false)Integer pageNum,
            @RequestParam(required = false,defaultValue = "0") Integer houseid,
                                 @RequestParam(required = false,defaultValue = "0") Integer uid,
                                 @RequestParam(required = false,defaultValue = "") String fkcontent,
                                 @RequestParam(required = false) Date startTime,
                                 @RequestParam(required = false) Date endTime){
        PageInfo<Wxfk> pageInfo = wxfkService.selectAllWxfk(pageNum, 10,id, houseid, uid, fkcontent, startTime, endTime);
        return ResultEntity.successWithoutData(pageInfo);

    }
    /*修改维修反馈*/
    @RequestMapping("house/updateWxfk")
    public ResultEntity updateWxfk(@RequestBody Wxfk wxfk){
        wxfk.setState(1);
        wxfk.setEnddate(new Date());
        int update = wxfkService.update(wxfk);
        return ResultEntity.successWithoutData("success");
    }
    /*删除维修反馈*/
    @RequestMapping("house/deleteWxfk")
    public ResultEntity deleteWxfk(Integer wxfkid){
        int i = wxfkService.deleteWxfk(wxfkid);
        if (i>0){
            java.lang.System.out.println("成功删除维修反馈"+wxfkid);
        }else{
            java.lang.System.err.println("删除维修反馈"+wxfkid+"失败");
        }
        return ResultEntity.successWithoutData("success");

    }
    /*查询公寓订单记录*/
    @Reference
    HouseOrderService houseOrderService;
    @RequestMapping("house/selectHouseOrders")
    public ResultEntity selectHouseOrders(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                          @RequestParam(defaultValue = "0",required = false) Integer houseid,
                                          @RequestParam(defaultValue = "",required = false)String orderno,
                                          @RequestParam(required = false) Date startTime,
                                          @RequestParam(required = false) Date endTime){

        PageInfo<Houseorder> pageInfo = houseOrderService.selectHouseOrders(pageNum, 10, houseid, orderno,startTime, endTime);
        return ResultEntity.successWithoutData(pageInfo);
    }
    /*删除公寓订单记录*/
    @RequestMapping("house/deleteHouseOrder")
    public ResultEntity deleteHouseOrder(Integer id){
        houseOrderService.deleteHouseOrder(id);
        return ResultEntity.successWithoutData("success");
    }
    /*查询公寓余额*/
    @Reference
    ManageService manageService;
    @RequestMapping("house/getHouseMoney")
    public ResultEntity getHouseMoney(Integer houseid){
        Manage manage = manageService.selectManageForHouse(houseid);
        return ResultEntity.successWithoutData(manage);

    }
    /*公寓余额提现*/
    @RequestMapping("house/getMoney")
    public ResultEntity getMoney(String bankNum,String money,Integer houseid) {
        Houseorder houseorder=new Houseorder();
        houseorder.setState(0);
        houseorder.setMoney(Double.parseDouble(money));
        houseorder.setProperties(1);
        houseorder.setRemark("提现至:"+bankNum);
        houseorder.setDate(new Date());
        houseorder.setOrderno(OrderNoUtils.getOrderNo());
        houseorder.setHouseid(houseid);
        houseOrderService.addHouseOrder(houseorder);
        Manage manage = manageService.selectManageForHouse(houseid);
        if (manage.getMoney()<Double.parseDouble(money)){
            return ResultEntity.successWithoutData("nomoney");
        }else{
            manage.setMoney(manage.getMoney()-Double.parseDouble(money));
            manageService.update(manage);
            PageInfo<Houseorder> pageInfo = houseOrderService.selectHouseOrders(1, 1, houseid, houseorder.getOrderno(), null, null);
            Houseorder newHouseOrder=pageInfo.getList().get(0);
            newHouseOrder.setState(1);
            int update = houseOrderService.update(newHouseOrder);
            if (update>0){
                return ResultEntity.successWithoutData("success");
            }else{
                return ResultEntity.successWithoutData("FAILD");
            }

        }

    }

    @Resource
    MailService mailService;
    /*通知群发*/
    @RequestMapping("house/note/fanout")
    public ResultEntity fanout(Integer type,String note,Integer houseid){
        House house = houseService.selectById(houseid);
        List<Liver> livers = liverService.selectLiverList();
        List<Liver> sendLivers=new ArrayList<>();
        for (Liver liver : livers) {
            if (liver.getHouseid()==houseid){
                sendLivers.add(liver);
            }
        }

        if (type==1){
            /*给所有邮箱注册用户发送邮件*/
            for (Liver liver : sendLivers) {
                if (liver.getPhone()==null||liver.getPhone().equals("")) {
                    mailService.sendSimpleMail(liver.getEmail(), house.getHousename() + "公寓通知邮件:", note);
                }
            }

        }
        if (type==2){

            /*给所有手机号注册用户发送邮件*/
            String phones="";
            for (Liver liver : sendLivers) {
                if (liver.getEmail() == null||liver.getEmail().equals("")) {
                    phones = phones+liver.getPhone()+",";

               /*    AliyunSms.sendSms(liver.getPhone(),note);*/
                }

            }
            phones=phones.substring(0,phones.length()-1);
        }
        if (type==3){
            /*给所有邮箱注册用户发送邮件*/
            for (Liver liver : sendLivers) {
                if (liver.getPhone()==null||liver.getPhone().equals("")) {
                    mailService.sendSimpleMail(liver.getEmail(), house.getHousename() + "公寓通知邮件:", note);
                }
            }
        }
        if (type==4){
            /*7天内入住的所有住户*/
            for (Liver liver : sendLivers) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(liver.getStarttime());
                long timeInMillis1 = calendar.getTimeInMillis();
                calendar.setTime(new Date());
                long timeInMillis2 = calendar.getTimeInMillis();
                long betweenDays =  (timeInMillis2 - timeInMillis1) / (1000L*3600L*24L);
                if (betweenDays<=7){
                    /*发送邮件*/
                    if (liver.getEmail()!=null&&!liver.getEmail().equals("")){
                        mailService.sendSimpleMail(liver.getEmail(),house.getHousename()+"公寓通知邮件",note);
                    }
                }
            }
        }
        if (type==5){
            /*7天内到期的所有住户*/
            for (Liver liver : sendLivers) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(liver.getStarttime());
                long timeInMillis1 = calendar.getTimeInMillis();
                calendar.setTime(new Date());
                long timeInMillis2 = calendar.getTimeInMillis();
                long betweenDays =  (timeInMillis1-timeInMillis2) / (1000L*3600L*24L);
                if (betweenDays<=7){
                    /*发送邮件*/
                   if (liver.getEmail()!=null&&!liver.getEmail().equals("")){
                       mailService.sendSimpleMail(liver.getEmail(),house.getHousename()+"公寓通知邮件",note);
                   }
                }
            }
        }
        return ResultEntity.successWithoutData("success");

    }
/*    @RequestMapping("test")
    public test test(){
        test test=new test();
        test.setHousename("housename");
        test.setNote("note");
        return test;
    }*/

    /*获取管理员列表*/
    @RequestMapping("house/getManages")
    public ResultEntity getManages(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                   @RequestParam(required = false,defaultValue = "0") Integer houseid,
                                   @RequestParam(required = false,defaultValue = "") String name,
                                   @RequestParam(required = false )Integer state,
                                   @RequestParam(required = false,defaultValue = "0")Integer id){
        PageInfo<Manage> manages = manageService.getManages(pageNum, 7, houseid, name,state,id);
        return ResultEntity.successWithoutData(manages);
    }
    /*修改管理员信息(审核 修改等)*/
    @RequestMapping("house/updateManage")
    public ResultEntity updateManage(@RequestBody Manage manage){
        manageService.update(manage);
        return ResultEntity.successWithoutData("success");

    }
    /*修改管理员密码*/
    @PostMapping("house/updateMPwd")
    public ResultEntity updateMpwd(@RequestBody Manage manage){
        manage.setPassword(CrowdFundingUtils.md5(manage.getPassword()));
        manageService.update(manage);
        return ResultEntity.successWithoutData("success");

    }

    /*增加管理员*/
    @PostMapping("house/addManage")
    public ResultEntity addManage(@RequestBody Manage manage){
        manage.setIsz(0);
        manage.setMoney(0.0);
        manage.setState(1);
        int i = manageService.addManage(manage);
        if (i==2){
            return ResultEntity.successWithoutData("success");
        }else{
            if (i==1){
                return ResultEntity.successWithoutData("管理员帐号已存在,请换个用户名尝试!");
            }else{
                return ResultEntity.successWithoutData("系统错误,请稍后重试");
            }
        }


    }


    /*删除管理员*/
    @RequestMapping("house/deleteManage")
    public ResultEntity deleteManage(Integer id){
        manageService.deleteManage(id);
        return ResultEntity.successWithoutData("success");

    }
    /*住宿延期*/
    @RequestMapping("house/longerLiverDay")
    public ResultEntity longerLiverDay(Integer liverid,Integer day){
        Liver liver = liverService.getLiverById(liverid);
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(liver.getEndtime());
        calendar.add(Calendar.DATE,day);
        liver.setEndtime(calendar.getTime());
        int update = liverService.update(liver);
        return ResultEntity.successWithoutData("success");
    }
    //账单催收(待完善)
    @RequestMapping("house/zdstateExe")
    public ResultEntity zdstateExe(Integer uid){
        Liver liverById = liverService.getLiverById(uid);
        liverById.setZdstate(1);
        liverService.update(liverById);
        return ResultEntity.successWithoutData("success");
    }













/*   @ExceptionHandler(value = Exception.class)
    public ResultEntity entity(){
        java.lang.System.err.println(new Date()+"时捕捉到了异常,在HouseController");
        return ResultEntity.failed("系统错误","MyHouse提示:抱歉,您当前的操作无法正常完成,可能是系统出现了故障,请稍等五分钟后重试,如若长时间无法操作,您可以发送邮件至lgp1022@foxmail.com与我们反馈,给您带来的不便我们深表歉意.祝您工作顺利,生活愉快.");
    }*/

}
